﻿Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.Text
Imports System.IO
Imports System.Drawing
Imports System.Web

Public Class Fecha
  Inherits TextBox
  Implements IScriptControl


  Dim ConCalendarioValor As Boolean = True
  Public Property ConCalendario() As Boolean
    Get
      Return ConCalendarioValor
    End Get
    Set(ByVal value As Boolean)
      ConCalendarioValor = value
    End Set
  End Property

  Dim DefectoValor As Date = Date.MinValue
  Public Property Defecto() As Date
    Get
      Return DefectoValor
    End Get
    Set(ByVal value As Date)
      DefectoValor = value
    End Set
  End Property

  Dim CssErrorValor As String = "Erroneo"
  Public Property CssError() As String
    Get
      Return CssErrorValor
    End Get
    Set(ByVal value As String)
      CssErrorValor = value
    End Set
  End Property

  Dim AceptaBlancoValor As Boolean = True
  Public Property AceptaBlanco() As Boolean
    Get
      Return AceptaBlancoValor
    End Get
    Set(ByVal value As Boolean)
      AceptaBlancoValor = value
    End Set
  End Property

  Dim AutoCompletarValor As TipoAutoCompletar = TipoAutoCompletar.Nada
  Public Property AutoCompletar() As TipoAutoCompletar
    Get
      Return AutoCompletarValor
    End Get
    Set(ByVal value As TipoAutoCompletar)
      AutoCompletarValor = value
    End Set
  End Property

  'Dim MensajeErrorValor As String = "Fecha erronea"
  'Public Property MensajeError() As String
  '  Get
  '    Return MensajeErrorValor
  '  End Get
  '  Set(ByVal value As String)
  '    MensajeErrorValor = value
  '  End Set
  'End Property

  Dim ValidandoValor As String = ""
  Public Property Validando() As String
    Get
      Return ValidandoValor
    End Get
    Set(ByVal value As String)
      ValidandoValor = value
    End Set
  End Property

  Dim IdFeriadosValor As String = ""
  Public Property IdFeriados() As String
    Get
      Return IdFeriadosValor
    End Get
    Set(ByVal value As String)
      IdFeriadosValor = value
    End Set
  End Property
  Dim AceptaFeriadosValor As Boolean = False
  Public Property AceptaFeriados() As Boolean
    Get
      Return AceptaFeriadosValor
    End Get
    Set(ByVal value As Boolean)
      AceptaFeriadosValor = value
    End Set
  End Property

  Dim ColumnaAtributoValor As String = ""
  Public Property ColumnaAtributo() As String
    Get
      Return ColumnaAtributoValor
    End Get
    Set(ByVal value As String)
      ColumnaAtributoValor = value
    End Set
  End Property

  Dim RangoDesdeValor As Date = Date.MinValue
  Public Property RangoDesde() As Date
    Get
      Return RangoDesdeValor
    End Get
    Set(ByVal value As Date)
      RangoDesdeValor = value
    End Set
  End Property
  Dim RangoHastaValor As Date = Date.MaxValue
  Public Property RangoHasta() As Date
    Get
      Return RangoHastaValor
    End Get
    Set(ByVal value As Date)
      RangoHastaValor = value
    End Set
  End Property

  Dim DiasProhibidosValor As TipoDiaSemana = TipoDiaSemana.Ninguno
  Public Property DiasProhibidos() As TipoDiaSemana
    Get
      Return DiasProhibidosValor
    End Get
    Set(ByVal value As TipoDiaSemana)
      DiasProhibidosValor = value
    End Set
  End Property

  Public Enum TipoAutoCompletar
    Nada
    Defecto
    Hoy
  End Enum
  Public Enum TipoDiaSemana
    Ninguno = -1
    Domingo = 1
    Lunes = 2
    Martes = 4
    Miercoles = 8
    Jueves = 16
    Viernes = 32
    Sabado = 64
  End Enum
  Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    If Not Me.DesignMode Then
      Dim SM As ScriptManager = ScriptManager.GetCurrent(Page)
      If SM Is Nothing Then
        Throw New HttpException("Debe existir un ScriptManager el la pagina")
      Else

        SM.RegisterScriptControl(Me)
      End If
    End If
    MyBase.OnPreRender(e)
  End Sub
  Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    If Not Me.DesignMode Then
      ScriptManager.GetCurrent(Me.Page).RegisterScriptDescriptors(Me)
    End If
    MyBase.Render(writer)
  End Sub
  Public Function GetScriptDescriptors() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptDescriptor) Implements System.Web.UI.IScriptControl.GetScriptDescriptors
    Dim descriptor As New ScriptControlDescriptor("MoniMisi2.Fecha", Me.ClientID)
    Dim descriptors As New List(Of ScriptDescriptor)
    descriptor.AddProperty("ConCalendario", ConCalendario)
    descriptor.AddProperty("DiasProhibidos", DiasProhibidos)
    descriptor.AddProperty("Defecto", Defecto)
    descriptor.AddProperty("RangoDesde", RangoDesde)
    descriptor.AddProperty("RangoHasta", RangoHasta)
    descriptor.AddProperty("CssError", CssError)
    descriptor.AddProperty("AceptaBlanco", AceptaBlanco)
    descriptor.AddProperty("AutoCompletar", [Enum].GetName(GetType(TipoAutoCompletar), AutoCompletar))
    descriptor.AddProperty("ColumnaAtributo", Me.ColumnaAtributo)
    descriptor.AddProperty("AceptaFeriados", Me.AceptaFeriados)
    'descriptor.AddProperty("MensajeError", MensajeError)
    descriptor.AddProperty("IdFeriados", IdFeriados)
    If Me.Validando <> String.Empty Then
      descriptor.AddEvent("Validando", Me.Validando)
    End If
    descriptors.Add(descriptor)
    Return descriptors
  End Function

  Public Function GetScriptReferences() As System.Collections.Generic.IEnumerable(Of System.Web.UI.ScriptReference) Implements System.Web.UI.IScriptControl.GetScriptReferences
    Dim scriptRef As New ScriptReference("MoniMisi2.Fecha.js", Funciones.NombreCompletoEnsamblado(Me.GetType, "MoniMisi2.Fecha"))
    scriptRef.NotifyScriptLoaded = False
    Dim scriptRefs As New List(Of ScriptReference)
    scriptRefs.Add(scriptRef)
    Return scriptRefs
  End Function
End Class
